package com.homegoods.goods.item;

import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.view.View;

import com.alibaba.android.arouter.launcher.ARouter;
import com.homegoods.classify.model.Constant;
import com.homegoods.goods.R;
import com.homegoods.goods.model.GoodsModel;
import com.homegoods.aroutercomment.ARouterPath;
import com.homegoods.resource.util.Utils;
import com.kedll.library.mvp.BaseItem;

import java.math.BigDecimal;

/**
 * @author QiQi
 * @ClassName: GoodsItem
 * @date 2018/9/18
 * @description
 */
public class GoodsItem extends BaseItem<GoodsModel> {
    public GoodsItem(GoodsModel data) {
        super(data);
        setOnClickListener(v -> ARouter.getInstance()
                .build(ARouterPath.PATH_GOODS_DETAIL).withString("sid", getData().getSid())
                .navigation());
    }


    public String getImgUrl() {
        return Constant.SERVER_URL + getData().getSmallPic();
    }

    public Spanned getTitle() {
        return Html.fromHtml(getData().getTitle());
//        return getData().getTitle();
    }

    public String getPrice() {
        return String.format("￥%s", getData().getNowPrice().setScale(2));
    }

    public String getActPrice() {
        if (getData().getPayCake().compareTo(BigDecimal.ZERO) == 0) {
            return "";
        } else {
            return String.format("￥%s", getData().getNowPrice().subtract(getData().getNowPrice().multiply(getData().getPayCake())));
        }
    }

    public int isShowActPrice() {
        if (getData().getPayCake().compareTo(BigDecimal.ZERO) == 0) {
            return View.GONE;
        }
        return View.VISIBLE;
    }

    public String getDayang() {
        if (getData().getPayCake().compareTo(BigDecimal.ZERO) == 0) {
            return "";
        } else {
            return String.format("%s积分", getData().getNowPrice().multiply(getData().getPayCake()));
        }

    }

    public String getShopName() {
        //add if & else shibo.zheng
        if (null == getData().getBusinessman()){
            return "";
        } else {
            return getData().getBusinessman().getTitle();
        }
    }

    public String getPayNum() {
        return String.format("%s人付款", getData().getSaleCount());
    }

    public int isExplode() {

        //TODO
//        return (getData().getLabel2() == 0) ? View.VISIBLE : View.GONE;
        return View.GONE;
    }

    @Override
    public int getLayout() {
        return R.layout.item_goods;
    }
}
